(function(e,t,r,i){"use strict";var n=function(){function e(t){babelHelpers.classCallCheck(this,e);this.grid=BX.Main.gridManager.getInstanceById(t.gridId);this.signedParameters=t.signedParameters;this.initAppendRowButton();this.initSaveButton();this.initGrid();this.initErrorAlert()}babelHelpers.createClass(e,[{key:"getGridBodyRows",value:function e(){return this.grid.getRows().getBodyChild()}},{key:"initGrid",value:function e(){var t=this;r.EventEmitter.subscribe("Grid::updated",(function(e){var r=e.getCompatData()[0];if(r&&r.getId()===t.grid.getId()){var i=10;setTimeout(t.initGridRows.bind(t),i)}}));this.initGridRows()}},{key:"initGridRows",value:function e(){var t=this.getGridBodyRows();if(t.length===0){for(var r=0;r<5;r++){this.appendNewRowToGrid()}}else{t.forEach((function(e){e.edit()}))}}},{key:"getGridValues",value:function e(){var t={};var r=0;this.getGridBodyRows().forEach((function(e){var i=parseInt(e.getId());if(isNaN(i)||!i){r++;i="n"+r}t[i]=e.getEditorValue()}));return t}},{key:"reloadGrid",value:function e(){this.grid.reload()}},{key:"initAppendRowButton",value:function e(){var t=this;var r=document.querySelector(".iblock-property-type-list-values-append-row");if(r){r.addEventListener("click",(function(e){e.preventDefault();t.appendNewRowToGrid()}))}}},{key:"appendNewRowToGrid",value:function e(){var t=this.grid.appendRowEditor();t.setId("")}},{key:"initSaveButton",value:function e(){var r=this;var i=document.querySelector("#ui-button-panel-save");if(i){i.addEventListener("click",function(){var e=babelHelpers.asyncToGenerator(regeneratorRuntime.mark((function e(n){return regeneratorRuntime.wrap((function e(o){while(1){switch(o.prev=o.next){case 0:n.preventDefault();o.next=3;return r.clearErrors();case 3:t.ajax.runComponentAction("bitrix:iblock.property.type.list.values","save",{data:{values:r.getGridValues()},mode:"class",signedParameters:r.signedParameters}).then((function(e){i.classList.remove("ui-btn-wait");r.reloadGrid()}))["catch"]((function(e){i.classList.remove("ui-btn-wait");r.showErrors(e.errors)}));case 4:case"end":return o.stop()}}}),e)})));return function(t){return e.apply(this,arguments)}}())}}},{key:"clearErrors",value:function e(){var t=this;return new Promise((function(e,r){var i=300;t.errorAlert.hide();setTimeout(e,i)}))}},{key:"showErrors",value:function e(t){this.errorAlert.setText(t.map((function(e){return e.message})).join("<br>"));this.errorAlert.renderTo(document.querySelector("#ui-button-panel"))}},{key:"initErrorAlert",value:function e(){this.errorAlert=new i.Alert({color:i.AlertColor.DANGER,animated:true,customClass:"iblock-property-type-list-values-errors-container"})}}]);return e}();t.Reflection.namespace("BX.Iblock").PropertyListValues=n})(this.window=this.window||{},BX,BX.Event,BX.UI);
//# sourceMappingURL=script.map.js